package oa.hleast.xswl.controller.app;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import oa.hleast.common.enums.QueryModeEnum;
import oa.hleast.common.result.Result;
import oa.hleast.common.result.ResultCode;
import oa.hleast.xswl.pojo.domain.SysCommonConfig;
import oa.hleast.xswl.pojo.domain.SysDictItem;
import oa.hleast.xswl.pojo.dto.SysDictItemDto;
import oa.hleast.xswl.service.ISysCommonConfigService;
import oa.hleast.xswl.service.ISysDictItemService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Api(tags = "【移动端】字典接口")
@RestController
@RequestMapping("/api.app/v1/dict-items")
@Slf4j
@AllArgsConstructor
public class DictItemController {

    private ISysDictItemService iSysDictItemService;
    private ISysCommonConfigService commonConfigService;

    @ApiOperation(value = "通过配置key获取配置信息", httpMethod = "GET")
    @GetMapping("/getDictItemDetailByConfigKey")
    Result<SysDictItemDto> getDictItemDetailByConfigKey(@RequestParam @NotBlank String configKey) {
        log.info("configKey = {}", configKey);

        SysCommonConfig commonConfig = commonConfigService.getByConfigKey(configKey);
        log.info("commonConfig = {}", commonConfig);

        SysDictItem dictItem = iSysDictItemService.getById(commonConfig.getValue());
        log.info("dictItem = {}", dictItem);

        SysDictItemDto sysDictItemDto = new SysDictItemDto();
        BeanUtil.copyProperties(dictItem, sysDictItemDto);

        return Result.success(sysDictItemDto);
    }
}
